package com.wx.chapter14.collections_;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @Author : 佩萁
 * Description :
 * @Create : 2023/8/11 - 10:53
 */
public class Collections_ {
    public static void main(String[] args) {
        //创建 ArrayList  集合，用于测试.
        List list = new ArrayList();
        list.add("tom");
        list.add("smith");
        list.add("king");
        list.add("milan");
        list.add("tom");
//        System.out.println(list);
//        Collections.reverse(list);
//        System.out.println(list);
//        for (int i = 0; i < 5; i++) {
//            Collections.shuffle(list);
//            System.out.println(list);
//        }
        System.out.println(list);
        Collections.sort(list, new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                return ((String)o2).length() - ((String)o1).length();
            }
        });
        System.out.println(list);
        Collections.swap(list,1,2);
        System.out.println(list);
    }
}
